package com.platform.modules.mall.activityV2.rule;


import com.platform.common.exception.BusinessException;
import com.platform.modules.mall.activity.rule.RuleFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 不同的领取方式。实现对应的接口RuleInterface，就能做到不同的领取效果
 *  1.活动中如果领取的方式存在了，就可以开发代码，只需要在前端处理方式就可以
 */
@Component
public class RuleFactoryV2 {

    @Resource(name = "drawGoodsRule")
    private DrawGoodsRule drawGoodsRule;
    @Resource(name = "directGoodsRule")
    private DirectGoodsRule directGoodsRule;
    @Resource(name = "pollingGoodsRule")
    private PollingGoodsRule pollingGoodsRule;

    public RuleInterface ruleInterface(int activityType){
        if (ActivityType.DIRECT_GOODS.getType().equals(activityType)) {
            /*直接领取商品的方式*/
            return directGoodsRule;
        }  else if (ActivityType.POLLING_GOODS.getType().equals(activityType)) {
            /*轮询发放的方式*/
            return pollingGoodsRule;
        }else if (ActivityType.BI_ZHONG.getType().equals(activityType)) {
            /*抽奖领取的方式*/
            return drawGoodsRule;
        }
        throw new BusinessException("该活动领取方式不存在");
    }

    private enum ActivityType {
        /**
         * 指定商品
         */
        DIRECT_GOODS(1),
        /**
         * 轮询商品
         */
        POLLING_GOODS(2),
        /**
         * 必中抽奖
         */
        BI_ZHONG(3);

        private Integer type;

        ActivityType(Integer type) {
            this.type = type;
        }

        public Integer getType() {
            return this.type;
        }
    }
}
